import { app, root } from "../apiRoot";
import { defHttp } from '@/utils/http';
import { AdminAddOrUpdateData, AiAccountBotListResult, AiAddOrUpdateData, AssistantInvitationCodeInfoResult, AuthorizedUserListResult, BotAdminPageListResult, BotStatisticsResult } from "./types";
import { IQuery } from "../types";
import { InvitationStatusEnum } from "@/enums/PublicEnum";

const Api = {
  aiAddOrUpdate: root + 'bot/addOrUpdate',
  aiAccountBotList: root + 'ai-user-account-bot/getAccountBotList',
  aiCutBot: root + 'ai-user-account-bot/cut/bot',
  authorizedUserList: root + 'ai-user-account-bot/authorizedUserList',
  aiAuthorizedAdd: root + 'bot/authorized/add',
  botAddOrUpdate: root + 'bot/addOrUpdate',
  getByIdSetingInfo: root + 'bot/getByIdSetingInfo',

  botAdminPageList: root + 'bot/account/admin/pageList',
  botAdminDel: root + 'bot/account/admin/del',
  adminAddOrUpdate: root + 'bot/account/admin/addOrUpdate',
  assistantInvitationCode: root + 'bot/account/admin/invitationCode',
  assistantInvitationCodeInfo: root + 'bot/invitation-user-code/getBotInfo',
  handleAssistantInvitation: root + 'bot/invitation-user-code/botAdmin/join',
  getBotStatistics: root + 'bot/getBotStatistics'
}

/**
 * @description 创建智能体
 * @date 06/03/2025
 * @export
 * @param {(Pick<AiAddOrUpdateData, 'name' | 'description'>)} data
 */
export function createAi(data: Pick<AiAddOrUpdateData, 'name' | 'description'>) {
  return defHttp.post({
    url: Api.aiAddOrUpdate,
    data,
  });
}

/**
 * @description 获取智能体列表
 * @date 06/03/2025
 * @export
 */
export function aiAccountBotList() {
  return defHttp.get<AiAccountBotListResult[]>({
    url: Api.aiAccountBotList,
  });
}

/**
 * @description 切换智能体
 * @date 06/03/2025
 * @export
 */
export function aiCutBot(data: { botId: number }) {
  return defHttp.post({
    url: Api.aiCutBot,
    data,
  }, {
    disableLoading: true
  });
}

/**
 * @description 获取授权用户列表
 * @date 08/03/2025
 * @export
 */
export function authorizedUserList() {
  return defHttp.get<AuthorizedUserListResult[]>({
    url: Api.authorizedUserList,
  });
}

/**
 * @description 授权创建智能体
 * @date 08/03/2025
 * @export
 */
export function aiAuthorizedAdd(data: { memberLeadingId: number }) {
  return defHttp.post({
    url: Api.aiAuthorizedAdd,
    data,
  });
}

/**
 * @description 添加或更新智能体高级设置
 * @date 12/03/2025
 * @export
 */
export function botAddOrUpdate(data: AiAddOrUpdateData) {
  return defHttp.post({
    url: Api.botAddOrUpdate,
    data,
  });
}

/**
 * @description 获取智能体高级设置
 * @date 12/03/2025
 * @export
 */
export function getBotAdvancedSettings() {
  return defHttp.get<AiAddOrUpdateData>({
    url: Api.getByIdSetingInfo,
  });
}

/**
 * @description 获取智能体管理员列表
 * @date 12/03/2025
 * @export
 */
export function botAdminPageList(data: IQuery) {
  return defHttp.get<BotAdminPageListResult[]>({
    url: Api.botAdminPageList,
    data,
  });
}

/**
 * @description 删除智能体管理员
 * @date 12/03/2025
 * @export
 */
export function botAdminDel(data: { id: number }) {
  return defHttp.post({
    url: Api.botAdminDel,
    data,
  });
}

/**
 * @description 添加或更新管理员
 * @date 13/03/2025
 * @export
 */
export function adminAddOrUpdate(data: AdminAddOrUpdateData) {
  return defHttp.post({
    url: Api.adminAddOrUpdate,
    data,
  });
}

/**
 * @description 获取管理员邀请码
 * @date 13/03/2025
 * @export
 */
export function assistantInvitationCode() {
  return defHttp.post<string>({
    url: Api.assistantInvitationCode,
  });
}

/**
 * @description 获取管理员邀请码信息
 * @date 13/03/2025
 * @export
 */
export function assistantInvitationCodeInfo(invitationCode: string) {
  return defHttp.get<AssistantInvitationCodeInfoResult>({
    url: Api.assistantInvitationCodeInfo + '/' + invitationCode,
  });
}

/**
 * @description 处理管理员邀请
 * @date 13/03/2025
 * @export
 */
export function handleAssistantInvitation(data: { code: string, status: InvitationStatusEnum }) {
  return defHttp.post({
    url: Api.handleAssistantInvitation,
    data,
  });
}

/**
 * @description 获取智能体统计数据
 * @date 2024
 * @export
 */
export function getBotStatistics() {
  return defHttp.get<BotStatisticsResult>({
    url: Api.getBotStatistics,
  });
}
